﻿using System;

namespace Hanhud.Security
{
    using Hanhud.Data.Providers;

    public sealed class CMembership
    {
        /// <summary>
        /// Change user's password
        /// </summary>
        /// <param name="username"></param>
        /// <param name="oldPassword"></param>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        public static bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            return CMembershipProvider.Instance.ChangePassword(username, oldPassword, newPassword);
        }

        public static bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
        {
            return false;
        }

        public static CMembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, out EMembershipCreateStatus createStatus)
        {
            CMembershipProvider.Instance.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, out createStatus);

            CMembershipUser newUser = new CMembershipUser();

            if (createStatus == EMembershipCreateStatus.Success)
            {
                newUser.UserName = username;
                newUser.IsLockedOut = true;
                newUser.Email = email;
            }

            return newUser;
        }

        public static bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            return false;
        }

        public static CMembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            return CMembershipProvider.Instance.FindUsersByEmail(emailToMatch, pageIndex, pageSize, out totalRecords);
        }

        public static CMembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            return CMembershipProvider.Instance.FindUsersByName(usernameToMatch, pageIndex, pageSize, out totalRecords);
        }

        public static CMembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            return CMembershipProvider.Instance.GetAllUsers(pageIndex, pageSize, out totalRecords);
        }

        public static int GetNumberOfUsersOnline()
        {
            return CMembershipProvider.Instance.GetNumberOfUsersOnline();
        }

        public static CMembershipUser GetUser(string username, bool userIsOnline)
        {
            return CMembershipProvider.Instance.GetUser(username, userIsOnline);
        }

        public static string GetUserNameByEmail(string email)
        {
            return CMembershipProvider.Instance.GetUserNameByEmail(email);
        }

        public static string ResetPassword(string username, string answer)
        {
            return CMembershipProvider.Instance.ResetPassword(username, answer);
        }

        public static bool UnlockUser(string userName)
        {
            return CMembershipProvider.Instance.UnlockUser(userName);
        }

        public static void UpdateUser(CMembershipUser user)
        {
            CMembershipProvider.Instance.UpdateUser(user);
        }

        public static bool ValidateUser(string username, string password)
        {
            return CMembershipProvider.Instance.ValidateUser(username, password);
        }
    }
}
